import 'package:flutter/material.dart';

/**
 * 滑动选择器
 */
class SlideDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SlideStateDemo();
  }
}

class SlideStateDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return SlideState();
  }
}

class SlideState extends State<SlideStateDemo> {
  double _sliderItemA = 0.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('SlideDemo'),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(8.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Slider(
                  value: _sliderItemA,
                  onChanged: (value) {
                    setState(
                      () {
                        _sliderItemA = value;
                      },
                    );
                  },
                  //当前进度的背景颜色
                  activeColor: Colors.blue,
                  //底部背景颜色
                  inactiveColor: Colors.blue.withOpacity(0.3),
                  max: 10.0,
                  min: 0.0,
                  //刻度等分
                  divisions: 10,
                  //滑动上方出现的气泡显示
                  label: '${_sliderItemA.toInt()}',
                ),
              ],
            ),
            SizedBox(
              height: 16.0,
            ),
            Text('_sliderItemA= $_sliderItemA'),
          ],
        ),
      ),
    );
  }
}
